package com.xiangge.domain;

public class Goods {
    private int id;
    private String name;
    private int stock;
    private double price;
    private boolean isOnShelf;

    public double calculatePrice(int quantity) {
        if (quantity <= 0 || quantity > stock) {
            throw new IllegalArgumentException("数量必须大于0且不能超过库存量");
        }
        return quantity * price;
    }

    // 修改库存数量的方法
    public void updateStock(int quantity) {
        if (quantity < 0) {
            throw new IllegalArgumentException("数量不能是负数");
        }
        stock = Math.max(0, stock - quantity); // 保证库存量不会变为负数
    }

    public Goods() {
    }
    public Goods(int id, String name, int stock, double price, boolean isOnShelf) {
        this.id = id;
        this.name = name;
        this.stock = stock;
        this.price = price;
        this.isOnShelf = isOnShelf;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public boolean getIsOnShelf() {
        return isOnShelf;
    }

    public void setIsOnShelf(boolean isOnShelf) {
        this.isOnShelf = isOnShelf;
    }
}
